import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout'
// 路由规则配置数组
const routes = [
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    children: [
      {
        path: 'category/:id',
        name: 'Category',
        component: () => import('@/views/Category')
      },
      {
        path: '', // path置空 将作为默认的二级路由显示
        name: 'Home',
        component: () => import('@/views/Home')
      },
      {
        path: 'goods/:id',
        name: 'Goods',
        component: () => import('@/views/Goods')
      },
      {
        path: 'cart',
        name: 'Cart',
        component: () => import('@/views/Cart')
      },
      {
        path: 'settlement',
        name: 'Settlement',
        component: () => import('@/views/Settlement')
      },
      {
        path: 'pay/:id',
        name: 'Pay',
        component: () => import('@/views/Pay')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login')
  }
]
// 创建路由实例
const router = createRouter({
  history: createWebHashHistory(), // 哈希路由模式
  routes
})

export default router
